package com.tutorialspoint;


import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

@SuppressWarnings({ "unused", "resource" })
public class MainApp {
	
//	private static ApplicationContext context;
	private static AbstractApplicationContext  context;
	
//	static Logger log = Logger.getLogger(MainApp.class.getName());
	
	static Log log = LogFactory.getLog(MainApp.class.getName());


	public static void main(String[] args) {
		/*XmlBeanFactory factory = new XmlBeanFactory
                (new ClassPathResource("Beans.xml"));
		HelloWorld obj = (HelloWorld) factory.getBean("helloWorld");
		obj.getMessage();*/
		
		/*context = new FileSystemXmlApplicationContext
				("E:/zzl/yonyou/test/SpringExample/src/Beans.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
	      obj.getMessage();*/
		
		 /*context = new ClassPathXmlApplicationContext("Beans.xml");
	      HelloWorld objA = (HelloWorld) context.getBean("helloWorld");
	      objA.setMessage("I'm object A");
	      objA.getMessage();
	      HelloWorld objB = (HelloWorld) context.getBean("helloWorld");
	      objB.getMessage();
	      context.registerShutdownHook();*/
		
		  /*context = new ClassPathXmlApplicationContext("Beans.xml");

	      HelloWorld objA = (HelloWorld) context.getBean("helloWorld");

	      objA.getMessage1();
	      objA.getMessage2();

	      HelloIndia objB = (HelloIndia) context.getBean("helloIndia");
	      objB.getMessage1();
	      objB.getMessage2();
	      objB.getMessage3();*/
		
		 /*context = new ClassPathXmlApplicationContext("Beans.xml");
	      TextEditor te = (TextEditor) context.getBean("textEditor");
	      te.spellCheck();*/


		 /* context = new ClassPathXmlApplicationContext("Beans.xml");
	      TextEditor te = (TextEditor) context.getBean("textEditor");
	      te.spellCheck();*/
		
		
		
		 /*context = 
	             new ClassPathXmlApplicationContext("Beans.xml");
	      JavaCollection jc=(JavaCollection)context.getBean("javaCollection");
	      jc.getAddressList();
	      jc.getAddressSet();
	      jc.getAddressMap();
	      jc.getAddressProp();*/


		 /*context = new ClassPathXmlApplicationContext("Beans.xml");
	      Student student = (Student) context.getBean("student");
	      System.out.println("Name : " + student.getName() );
	      System.out.println("Age : " + student.getAge() );*/
		
		
		 /*context = new ClassPathXmlApplicationContext("Beans.xml");
	      Profile profile = (Profile) context.getBean("profile");
	      profile.printAge();
	      profile.printName();*/
		
		
//		 context = 
//                new ClassPathXmlApplicationContext("Beans.xml");
//		HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
//		obj.getMessage();
//		context.registerShutdownHook();
		
		
		/* ApplicationContext ctx = 
				   new AnnotationConfigApplicationContext(HelloWorldConfig.class); 
				   HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
				   helloWorld.setMessage("Hello World!");
				   helloWorld.getMessage();*/
				   
				   
	  /* AnnotationConfigApplicationContext ctx = 
			   new AnnotationConfigApplicationContext();
			   ctx.register(AppConfig.class, OtherConfig.class);
			   ctx.register(AdditionalConfig.class);
			   ctx.refresh();
			   MyService myService = ctx.getBean(MyService.class);
			   myService.doStuff();*/

		
		
	/*	ApplicationContext ctx = 
			      new AnnotationConfigApplicationContext(HelloWorldConfig.class);

			      HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

			      helloWorld.setMessage("Hello World!");
			      helloWorld.getMessage();*/
		
		
//		ApplicationContext ctx = 
//			      new AnnotationConfigApplicationContext(TextEditorConfig.class);
//
//			      TextEditor te = ctx.getBean(TextEditor.class);
//
//			      te.spellCheck();
		
		
		/*ApplicationContext ctx = 
				   new AnnotationConfigApplicationContext(ConfigB.class);
				   // now both beans A and B will be available...
				   A a = ctx.getBean(A.class);
				   B b = ctx.getBean(B.class);*/
		
		
		
		/* ConfigurableApplicationContext context = 
			      new ClassPathXmlApplicationContext("Beans.xml");

			      // Let us raise a start event.
			      context.start();

			      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

			      obj.getMessage();

			      // Let us raise a stop event.
			      context.stop();*/
		
		
		
		/*ConfigurableApplicationContext context = 
			      new ClassPathXmlApplicationContext("Beans.xml");    
			      CustomEventPublisher cvp = 
			      (CustomEventPublisher) context.getBean("customEventPublisher");
			      cvp.publish();  
			      cvp.publish();*/
		
		
		
		/* ApplicationContext context = 
	             new ClassPathXmlApplicationContext("Beans.xml");
	      Student student = (Student) context.getBean("student");
	      student.getName();
	      student.getAge();      
	      student.printThrowException();
*/
		
		
	/*	ApplicationContext context = 
	             new ClassPathXmlApplicationContext("Beans.xml");
	      Student student = (Student) context.getBean("student");
	      student.getName();
	      student.getAge();     
	      student.printThrowException();*/



//	      ApplicationContext context = 
//	             new ClassPathXmlApplicationContext("Beans.xml");
//	      StudentJDBCTemplate studentJDBCTemplate = 
//	      (StudentJDBCTemplate)context.getBean("studentJDBCTemplate");    
	      /*System.out.println("------Records Creation--------" );
	      studentJDBCTemplate.create("Zara", 11);
	      studentJDBCTemplate.create("Nuha", 2);
	      studentJDBCTemplate.create("Ayan", 15);
	      System.out.println("------Listing Multiple Records--------" );
	      List<Student> students = studentJDBCTemplate.listStudents();
	      for (Student record : students) {
	         System.out.print("ID : " + record.getId() );
	         System.out.print(", Name : " + record.getName() );
	         System.out.println(", Age : " + record.getAge());
	      }
	      System.out.println("----Updating Record with ID = 2 -----" );
	      studentJDBCTemplate.update(2, 20);
	      System.out.println("----Listing Record with ID = 2 -----" );
	      Student student = studentJDBCTemplate.getStudent(2);
	      System.out.print("ID : " + student.getId() );
	      System.out.print(", Name : " + student.getName() );
	      System.out.println(", Age : " + student.getAge()); */    
	      
//	      StudentDAO studentJDBCTemplate = 
//	    	      (StudentDAO)context.getBean("studentJDBCTemplate");     
//	      System.out.println("------Records creation--------" );
//	      studentJDBCTemplate.create("Zara", 11, 99, 2010);
//	      studentJDBCTemplate.create("Nuha", 20, 97, 2010);
//	      studentJDBCTemplate.create("Ayan", 25, 100, 2011);
//	      System.out.println("------Listing all the records--------" );
//	      List<StudentMarks> studentMarks = studentJDBCTemplate.listStudentsMarks();
//	      for (StudentMarks record : studentMarks) {
//	         System.out.print("ID : " + record.getId() );
//	         System.out.print(", Name : " + record.getName() );
//	         System.out.print(", Marks : " + record.getMarks());
//	         System.out.print(", Year : " + record.getYear());
//	         System.out.println(", Age : " + record.getAge());
//	      }
		
		
		
		
		ApplicationContext context = 
	             new ClassPathXmlApplicationContext("Beans.xml");
	      log.info("Going to create HelloWord Obj");
	      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
	      obj.getMessage();
	      log.info("Exiting the program");


	   



	   }


}
